Skip to content

Add API to list coopMat/coopVec types and combinations#10076

Open
cmarcelo wants to merge 4 commits intoshader-slang:masterfrom
cmarcelo:cmat-metadata
Open

Add API to list coopMat/coopVec types and combinations#10076
cmarcelo wants to merge 4 commits intoshader-slang:masterfrom
cmarcelo:cmat-metadata

Conversation

@cmarcelo
Copy link
Copy Markdown
Contributor

@cmarcelo cmarcelo commented Feb 18, 2026

Expose cooperative matrix and cooperative vector metadata through
a new ICooperativeTypesMetadata interface queried from IMetadata.

This information can be used to query the combinations of types that
the graphics driver supports.

Closes #10021.

@cmarcelo cmarcelo requested a review from a team as a code owner February 18, 2026 22:43
Copilot AI review requested due to automatic review settings February 18, 2026 22:43
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 18, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request adds comprehensive support for cooperative matrix and vector operations across the Slang compiler. It introduces new public API types and metadata interfaces for exposing cooperative type information, extends IR with five new cooperative instructions and validation logic, implements codegen for multiple targets (CUDA OptiX, HLSL, SPIR-V), and adds three new scalar types (BFloat16, FloatE4M3, FloatE5M2) plus pointer-sized integer types.

Changes

Cohort / File(s) Summary
Public API & Metadata Interfaces
include/slang.h, source/compiler-core/slang-artifact-associated-impl.h, source/compiler-core/slang-artifact-associated-impl.cpp
Added public enumerations (SlangScope, SlangCooperativeMatrixUse, SlangCooperativeVectorMatrixLayout), scalar types (BFloat16, FloatE4M3, FloatE5M2, IntPtr, UIntPtr), cooperative metadata structs (CooperativeMatrixType, CooperativeMatrixCombination, CooperativeVectorType, CooperativeVectorCombination), and new ICooperativeTypesMetadata interface. Extended ArtifactPostEmitMetadata to implement this interface with corresponding query methods and storage lists.
IR Instructions & Validation
source/slang/slang-ir-insts.lua, source/slang/slang-ir-insts-stable-names.lua, source/slang/slang-ir-validate.h, source/slang/slang-ir-validate.cpp, source/slang/slang-ir-metadata.h, source/slang/slang-ir-metadata.cpp
Defined five new IR instructions (CoopMatMulAdd, CoopVecMatMul, CoopVecMatMulAdd, CoopVecOuterProductAccumulate, CoopVecReduceSumAccumulate) with operand schemas, added comprehensive validation logic including operand count checks and type constraints, and implemented cooperative metadata collection from IR with mapping utilities for scalar types and enums.
SPIR-V Codegen
source/slang/slang-emit-spirv.cpp
Implemented SPIR-V emission for all five cooperative instructions with proper capability/extension declarations, operand mask derivation, component-type and layout mapping to SPIR-V enums, and validation of transpose/stride parameters.
CUDA & OptiX Codegen
source/slang/slang-emit-cuda.cpp, prelude/slang-cuda-prelude.h
Added CUDA codegen for cooperative vector ops targeting OptiX with mapped enum types, intrinsic calls, feature gating diagnostics, and WMMA validation. Updated CUDA prelude templates to use OptiX enums directly instead of Slang integer codes, removing compatibility translation layer.
HLSL Codegen
source/slang/slang-emit-hlsl.h, source/slang/slang-emit-hlsl.cpp
Added HLSL codegen support with new mapping helpers (emitMappedCoopVecComponentType, emitMappedCoopVecMatrixLayout) and statement handlers emitting HLSL builtin calls (__builtin_MatVecMul, __builtin_MatVecMulAdd, __builtin_OuterProductAccumulate, __builtin_VectorAccumulate).
C-Like & Slang Prelude
source/slang/slang-emit-c-like.cpp, source/slang/hlsl.meta.slang
Updated C-like emitter to handle cooperative ops as statements rather than expressions, and refactored Slang prelude to use intrinsic-backed entry points instead of per-target branching, removing SPIR-V/CUDA/HLSL assembly paths and legacy mutation helpers.
Type & Reflection Support
source/slang/slang-reflection-api.cpp, source/slang/slang-reflection-json.cpp, source/core/slang-type-text-util.cpp, source/slang/slang-ir.cpp, source/slang/slang-ir.h
Extended reflection to recognize and handle new scalar types, updated scalar-type name mappings and JSON emission, added new scalar cases to C++ TypeReflection::ScalarType enum, updated IR module version compatibility to 13, and marked cooperative multiply ops as side-effect-free.
Emission Integration
source/slang/slang-emit.cpp
Integrated cooperative validation and metadata collection into the post-link IR pipeline.
WASM & Test Support
source/slang-wasm/slang-wasm-bindings.cpp, tools/slang-unit-test/unit-test-cooperative-type-metadata.cpp, tools/slang-unit-test/unit-test-special-scalar-reflection.cpp
Extended WASM bindings to export new scalar type constants, added comprehensive cooperative metadata unit tests validating type counts and combinations, and added reflection tests for special scalar types.
Shader Codegen Tests
tests/cooperative-matrix/mat-mul-add-cuda-codegen.slang, tests/cooperative-vector/matrix-mul-hlsl-codegen.slang, tests/cooperative-vector/matrix-mul-spirv-codegen.slang, tests/cooperative-vector/training-cuda-codegen.slang, tests/cooperative-vector/training-hlsl-codegen.slang, tests/cooperative-vector/training-spirv-codegen.slang
Added shader test files validating codegen for cooperative matrix/vector operations across CUDA, HLSL, and SPIR-V targets with FileCheck expectations.
Diagnostic Tests
tests/cuda/optix-coopvec.slang, tests/cuda/optix-coopvec-packed-input-diagnostic.slang, tests/cuda/optix-coopvec-transpose-diagnostic.slang
Added CUDA codegen tests verifying unsupported cooperative vector intrinsic diagnostics and training operation code patterns.
Tool Utilities
tools/gfx/slang.slang, tools/render-test/shader-input-layout.cpp, tools/slang-test/slang-test-main.cpp
Extended GPU graphics tool with new scalar type enum, updated render test to handle new scalar types with conversion helpers, and extended comparison utility to treat new float formats as floating-point.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.85% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding an API to expose and list cooperative matrix/vector types and their combinations.
Description check ✅ Passed The PR description clearly relates to the changeset, describing the addition of ICooperativeTypesMetadata interface and cooperative matrix/vector metadata exposure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a new API to expose cooperative matrix type metadata, allowing applications to query which cooperative matrix type combinations are used in compiled shaders. This addresses issue #10021, where applications need to verify driver support for specific cooperative matrix type combinations used in shaders.

Changes:

  • Adds new public API types (SlangScope, SlangCooperativeMatrixUse, SlangCooperativeComponentType, SlangCooperativeMatrixType) and ICooperativeMatrixMetadata interface to slang.h
  • Implements metadata collection that recursively scans IR to identify all cooperative matrix types used in the compiled code
  • Includes comprehensive unit tests for both the new cooperative matrix metadata API and the binarySearch changes from dependency PRs

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
include/slang.h Adds new enums, struct, and interface for querying cooperative matrix types used in compiled shaders
source/compiler-core/slang-artifact-associated-impl.h Extends ArtifactPostEmitMetadata to implement ICooperativeMatrixMetadata interface
source/compiler-core/slang-artifact-associated-impl.cpp Implements the cooperative matrix metadata query methods with proper error handling
source/slang/slang-ir-metadata.cpp Adds IR type conversion helpers and recursive metadata collection for cooperative matrix types
source/core/slang-list.h Updates binarySearch to return bitwise negation of insertion index on miss (from PR #10048)
source/slang/slang-check-decl.cpp Replaces binarySearch with indexOf for declaration ordering (from PR #10047)
source/slang/slang-language-server-auto-format.cpp Updates exclusion range check to use >= 0 instead of != -1 (from PR #10048)
tools/slang-unit-test/unit-test-cooperative-type-metadata.cpp Comprehensive tests for the cooperative matrix metadata API
tools/slang-unit-test/unit-test-list.cpp Unit tests for the updated binarySearch behavior

@cmarcelo
Copy link
Copy Markdown
Contributor Author

Some context for this PR in #10021 (comment).

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@source/compiler-core/slang-artifact-associated-impl.cpp`:
- Around line 283-293: ArtifactPostEmitMetadata::getInterface is returning the
wrong interface pointer for the slang::IMetadata GUID (it returns
IArtifactPostEmitMetadata*), violating COM rules; update the GUID checks so that
when guid == slang::IMetadata::getTypeGuid() you return
static_cast<slang::IMetadata*>(this), when guid ==
IArtifactPostEmitMetadata::getTypeGuid() you return
static_cast<IArtifactPostEmitMetadata*>(this), and keep the ISlangUnknown,
ICastable and slang::ICooperativeMatrixMetadata cases returning their
corresponding static_casts so each GUID returns the correctly typed interface
pointer.

In `@source/slang/slang-check-decl.cpp`:
- Around line 3581-3582: The two indexOf() results (from
ancestor->getMembers().indexOf(subAncestor) and indexOf(supAncestor)) must be
validated for -1 before being used in arithmetic; update the code to check for
-1 and either assert (e.g., SLANG_ASSERT) or apply the same fallback/ordering
logic as used in _compareDeclsInCommonParentByOrderOfDeclaration() so a missing
member does not produce incorrect ordering. Locate the variables subIndex and
supIndex in this block and add the check/early-return or normalized ordering
fallback when either index is -1, and log or assert with clear context
referencing subAncestor/supAncestor to aid debugging.

Comment thread source/compiler-core/slang-artifact-associated-impl.cpp Outdated
Comment thread source/slang/slang-check-decl.cpp
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tools/slang-unit-test/unit-test-cooperative-type-metadata.cpp`:
- Around line 37-50: The test must guard and skip when SPIR-V or the
spvCooperativeMatrixKHR capability is unavailable; before proceeding with
targetDesc/compilation use the project's test-skip pattern (SLANG_IGNORE_TEST)
to check that globalSession->findProfile("spirv_1_6") is non-null and that
int32_t(globalSession->findCapability("spvCooperativeMatrixKHR")) is non-zero
(or otherwise indicates support), and if either check fails call
SLANG_IGNORE_TEST with an explanatory message instead of continuing; update the
logic around globalSession, targetDesc.format (SLANG_SPIRV), and
capabilityOption so the test is skipped early when those features are absent.

Comment thread tools/slang-unit-test/unit-test-cooperative-type-metadata.cpp Outdated
Copy link
Copy Markdown
Collaborator

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR wouldn't provide the information needed to query the combination of types that the graphics driver supports.

Comment thread source/compiler-core/slang-artifact-associated-impl.h Outdated
Comment thread include/slang.h Outdated
Comment thread include/slang.h Outdated
Comment thread include/slang.h Outdated
Comment thread include/slang.h Outdated
Comment thread include/slang.h
@jkwak-work jkwak-work self-assigned this Feb 19, 2026
@jkwak-work jkwak-work marked this pull request as draft February 19, 2026 00:41
Comment thread include/slang.h Outdated
Comment thread include/slang.h
Comment thread include/slang.h Outdated
Comment thread include/slang.h
Comment thread include/slang.h Outdated
Comment thread include/slang.h Outdated
@cmarcelo cmarcelo changed the title Add API to identify what cooperative matrix types were used Add API to list coopMat/coopVec types and combinations Feb 22, 2026
@cmarcelo
Copy link
Copy Markdown
Contributor Author

@coderabbitai summary

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 22, 2026

✅ Actions performed

Summary regeneration triggered.

Comment thread source/slang/slang-language-server-auto-format.cpp Outdated
Comment thread include/slang.h Outdated
Comment thread source/slang/slang-check-decl.cpp
Comment thread source/slang/slang-ir-metadata.cpp Outdated
Comment thread include/slang.h Outdated
@jkwak-work jkwak-work added the pr: non-breaking PRs without breaking changes label Feb 24, 2026
Copy link
Copy Markdown
Collaborator

@csyonghe csyonghe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I think we need to refactor the way coopMatMulAdd and other coop-vec intrinsics are implemented in the compiler first. We need to move the lowering logic from hlsl.meta.slang (library code) into each backends first so we can map each instrinsics to its dedicated slang IR opcode to simplify the meta data collection logic.

Comment thread source/slang/slang-check-decl.cpp
Comment thread source/slang/slang-ir-metadata.cpp Outdated
Comment thread source/slang/slang-ir-metadata.cpp Outdated
Comment thread include/slang.h Outdated
@jkwak-work
Copy link
Copy Markdown
Collaborator

@cmarcelo , were you able to make some progress on this PR?
Can you share some update?

@cmarcelo
Copy link
Copy Markdown
Contributor Author

cmarcelo commented Mar 5, 2026

@cmarcelo , were you able to make some progress on this PR? Can you share some update?

Working on the suggestions. Will update PR here in the next few days.

github-actions[bot]

This comment was marked as outdated.

@cmarcelo cmarcelo force-pushed the cmat-metadata branch 2 times, most recently from 01070ec to a00945c Compare March 9, 2026 03:11
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@cmarcelo cmarcelo force-pushed the cmat-metadata branch 2 times, most recently from 8d6a9d6 to ae3fd3c Compare April 1, 2026 15:13
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@cmarcelo cmarcelo force-pushed the cmat-metadata branch 2 times, most recently from 40f4137 to 652560c Compare April 9, 2026 04:10
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@cmarcelo
Copy link
Copy Markdown
Contributor Author

@jkwak-work ping

@jkwak-work
Copy link
Copy Markdown
Collaborator

Sorry for the delay. I was OOTO for a week.
I will review this as early as I can.

Expose cooperative matrix and cooperative vector metadata through
a new `ICooperativeTypesMetadata` interface queried from `IMetadata`.

This information can be used to query the combinations of types that
the graphics driver supports.

Closes shader-slang#10021.
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

Comment thread include/slang.h
Comment on lines +861 to +867
enum SlangScope : SlangScopeIntegral
{
SLANG_SCOPE_NONE,
SLANG_SCOPE_THREAD,
SLANG_SCOPE_WAVE,
SLANG_SCOPE_THREAD_GROUP,
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this same to the one we already have?

// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_scope_id
// must be 32 bit to match SPIR-V
enum class MemoryScope : int32_t
{
CrossDevice = 0,
Device = 1,
Workgroup = 2,
Subgroup = 3,
Invocation = 4,
QueueFamily = 5,
ShaderCall = 6,
};

LLMs are also point problems on this enum.
I think the enum name should be more like MemoryScope rather than just Scope.
And the values should match to the internal and SPIRV values.

Comment thread source/slang/slang-emit.cpp
Comment on lines +2265 to +2267
// Runs after target-specific lowering so it only captures cooperative types that remain
// as native constructs visible to the driver (see ICooperativeTypesMetadata docs).
SLANG_PASS(collectCooperativeMetadata, *metadata);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip this pass when the cooperative capability is not used or cooperative-vector or cooperative-matrix types are not found earlier.

List<slang::CooperativeMatrixType> m_cooperativeMatrixTypes;
List<slang::CooperativeMatrixCombination> m_cooperativeMatrixCombinations;
List<slang::CooperativeVectorType> m_cooperativeVectorTypes;
List<slang::CooperativeVectorCombination> m_cooperativeVectorCombinations;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if List is a right container for this when you want to maintain the sorted order.
Although the name List sounds like a linked-list but it is more like std::vector.
The cost of inserting in the middle will be higher than you may expected.

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 🔴 Has issues — 1 bug, 3 gaps, 1 question

This PR adds ICooperativeTypesMetadata, a new COM interface for querying cooperative matrix/vector types and multiply-add combinations from compiled shader metadata. The implementation collects metadata from IR after target-specific lowering via a new collectCooperativeMetadata pass. The main correctness concern is the use of unchecked cast<> in the metadata collection which can crash in release builds if IR invariants don't hold; the remaining findings are about namespace hygiene, documentation, and test coverage for key internal invariants.

Changes Overview

Public API (include/slang.h)

  • What changed: Added SlangScope enum, four new structs (CooperativeMatrixType, CooperativeMatrixCombination, CooperativeVectorType, CooperativeVectorCombination), and a new ICooperativeTypesMetadata COM interface with count+getByIndex methods for each type/combination list.

Metadata implementation (source/slang/slang-ir-metadata.cpp, slang-ir-metadata.h)

  • What changed: Added collectCooperativeMetadata pass that walks the IR breadth-first after target-specific lowering, extracts cooperative matrix/vector types and multiply-add combinations, and stores them in sorted deduplicated lists on ArtifactPostEmitMetadata.

Metadata storage (source/compiler-core/slang-artifact-associated-impl.cpp, .h)

  • What changed: ArtifactPostEmitMetadata now inherits ICooperativeTypesMetadata, stores four List<> members for cooperative types/combinations, and implements the eight get-count/get-by-index methods with null-pointer and bounds validation. COM getInterface updated for the new GUID.

Pipeline integration (source/slang/slang-emit.cpp)

  • What changed: collectCooperativeMetadata invoked after target-specific lowering in linkAndOptimizeIR, so only backends that retain native cooperative types (SPIRV, HLSL, CUDA+OptiX) report non-empty metadata.

Tests (tools/slang-unit-test/unit-test-cooperative-type-metadata.cpp)

  • What changed: New 861-line unit test file covering subgroup/workgroup matrix metadata, vector type/combination metadata, training operations, mixed training+non-training, lowered targets (plain CUDA), and empty shaders across SPIRV/HLSL/CUDA targets.
Findings (5 total)
Severity Location Finding
🔴 Bug slang-ir-metadata.cpp:469 cast<> assumes prior validation; crashes in release on malformed IR
🟡 Gap slang-ir-metadata.cpp:13 operator< in slang namespace for public types risks ODR violations
🟡 Gap include/slang.h:860 New SlangScope enum lacks documentation
🟡 Gap unit-test-cooperative-type-metadata.cpp:831 No tests for deduplication or maxSize merge logic
🔵 Question include/slang.h:4509 .use defaults to USE_A rather than a sentinel value

Comment on lines +468 to +469
IRIntegerValue packingFactorValue =
cast<IRIntLit>(matMulAdd->getInputInterpretationPackingFactor())->getValue();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: Unsafe cast<> usage assumes prior validation holds unconditionally

Three call sites in the cooperative metadata collection use cast<IRIntLit> / cast<IRBoolLit> (here, line 483 for getTranspose(), and line 559 for getSaturatingAccumulation()) based on the comment that validateCooperativeOperations guarantees operand literal types. However, cast<> only asserts in debug builds — in release builds a null or wrong-type operand would silently produce a null pointer and immediately dereference it, causing a crash.

The assumption that validation always precedes this pass is fragile: any future IR pass inserted between validateCooperativeOperations and collectCooperativeMetadata could create or modify cooperative instructions without re-validation. The rest of this file (e.g., _getCooperativeMatrixType at lines 309-341) already uses the defensive as<IRIntLit> + null-check pattern consistently.

Example: If a future optimization pass between validation and metadata collection performs constant folding that replaces an IRIntLit with a different IR node type, cast<IRIntLit>(nullptr) returns null in release builds, and ->getValue() dereferences it.

Suggested fix:

auto packingLit = as<IRIntLit>(matMulAdd->getInputInterpretationPackingFactor());
if (!packingLit)
    return;
IRIntegerValue packingFactorValue = packingLit->getValue();

Apply the same pattern to the cast<IRBoolLit> calls for getTranspose() and getSaturatingAccumulation().

// Define operator< for public cooperative type structs, used internally.
namespace slang
{
bool operator<(const CooperativeMatrixType& a, const CooperativeMatrixType& b)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Gap: operator< defined in slang namespace for public API types

These operator< overloads are defined in the slang namespace for structs declared in the public header include/slang.h. While they are only used internally for sorted insertion within this .cpp file, defining them at namespace scope means they participate in ADL for these types. If any other translation unit (or a downstream consumer) defines a different operator< for the same types in namespace slang, it would be an ODR violation.

Suggestion: Move the comparison logic into an anonymous namespace using named comparator structs or lambdas, and pass them explicitly to the _insertSortedUnique/lowerBound calls. This keeps the ordering internal to this file without polluting the slang namespace:

namespace {
struct CooperativeMatrixTypeLess {
    bool operator()(const slang::CooperativeMatrixType& a,
                    const slang::CooperativeMatrixType& b) const { /* ... */ }
};
} // anonymous namespace

Comment thread include/slang.h
Comment on lines +860 to +865
typedef SlangUInt32 SlangScopeIntegral;
enum SlangScope : SlangScopeIntegral
{
SLANG_SCOPE_NONE,
SLANG_SCOPE_THREAD,
SLANG_SCOPE_WAVE,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Gap: New public enum SlangScope lacks documentation

This is a new public API enum that maps GPU execution scopes for cooperative operations. Unlike the struct fields and the ICooperativeTypesMetadata interface (which have doc comments), the enum values have no documentation. Users need to understand the mapping to GPU concepts (thread = invocation, wave = subgroup, thread group = workgroup) and how these correspond to Vulkan/HLSL scopes.

Suggestion: Add a brief doc comment and per-value annotations:

/** Cooperative type execution scope.
 * Specifies the scope of threads that cooperate in matrix/vector operations.
 */
typedef SlangUInt32 SlangScopeIntegral;
enum SlangScope : SlangScopeIntegral
{
    SLANG_SCOPE_NONE,         ///< Invalid/unspecified scope
    SLANG_SCOPE_THREAD,       ///< Single invocation
    SLANG_SCOPE_WAVE,         ///< Subgroup/wave scope
    SLANG_SCOPE_THREAD_GROUP, ///< Workgroup/thread group scope
};

}
}

SLANG_UNIT_TEST(cooperativeMetadataEmptyShader)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Gap: No test for deduplication or cooperative vector maxSize merging

The implementation has two key invariants that are not directly validated by any test:

  1. Sorted unique insertion (_insertSortedUnique): If the same cooperative matrix type appears in multiple IR instructions, the metadata should contain it exactly once. The existing tests implicitly exercise this (types shared across matmul operands), but no test explicitly verifies that duplicate types are deduplicated — if the sorted-insertion logic regresses, the existing tests wouldn't necessarily catch it because they only check expected counts.

  2. maxSize merging (_insertOrUpdateCooperativeVectorType): When the same component type appears with different vector sizes (e.g., CoopVec<4, float> and CoopVec<8, float>), the implementation merges them into one entry with maxSize = max(4, 8) = 8. No test validates this merge behavior. Similarly, the usedForTrainingOp OR-merging when a type appears in both training and non-training contexts is only tested with the mixed test — but that test doesn't verify the maxSize is the maximum across both uses.

Suggestion: Add a targeted test that uses the same cooperative matrix type in multiple operations and asserts the type count is exactly 1 (not 2). Add a second test that uses the same vector component type with sizes 4, 8, 16 and asserts maxSize == 16.

Comment thread include/slang.h
uint32_t rowCount = 0;
uint32_t columnCount = 0;

SlangCooperativeMatrixUse use = SLANG_COOPERATIVE_MATRIX_USE_A;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Question: Default .use = SLANG_COOPERATIVE_MATRIX_USE_A for invalid types

All other fields in CooperativeMatrixType default to zero/NONE to indicate "not valid," but .use defaults to SLANG_COOPERATIVE_MATRIX_USE_A (value 0) because the SlangCooperativeMatrixUse enum has no NONE sentinel. This means a default-constructed or partially-initialized struct has a field that looks valid (USE_A) even when the struct is logically invalid (componentType == NONE).

The doc comment says componentType == NONE is the validity check, so this is consistent — but it could confuse callers who inspect .use without first checking componentType. Is this intentional, or would it be worth adding a SLANG_COOPERATIVE_MATRIX_USE_NONE sentinel to the existing enum (recognizing that changes the enum layout)?

@jkwak-work
Copy link
Copy Markdown
Collaborator

@cmarcelo , can you address some of my concerns?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a way to know what types are used for CoopVec/Mat operations

5 participants